import { createRouter, createWebHistory } from 'vue-router'

// 管理端页面
const AdminLogin = () => import('../views/admin/Login.vue')
const AdminDashboard = () => import('../views/admin/Dashboard.vue')
const AdminStudents = () => import('../views/admin/Students.vue')
const AdminMajors = () => import('../views/admin/Majors.vue')
const AdminClasses = () => import('../views/admin/Classes.vue')
const AdminDormitory = () => import('../views/admin/Dormitory.vue')
const AdminRegistration = () => import('../views/admin/Registration.vue')
const AdminFinance = () => import('../views/admin/Finance.vue')
const AdminNotices = () => import('../views/admin/Notices.vue')

// 学生端页面
const StudentLogin = () => import('../views/student/Login.vue')
const StudentHome = () => import('../views/student/Home.vue')
const StudentInfoSubmit = () => import('../views/student/InfoSubmit.vue')
const StudentPayment = () => import('../views/student/Payment.vue')
const StudentInfoQuery = () => import('../views/student/InfoQuery.vue')
const StudentProfile = () => import('../views/student/Profile.vue')
const StudentNotices = () => import('../views/student/Notices.vue')
const StudentSchedule = () => import('../views/student/Schedule.vue')
const StudentContact = () => import('../views/student/Contact.vue')

const routes = [
  {
    path: '/',
    redirect: '/admin/login'
  },
  // 管理端路由
  {
    path: '/admin',
    children: [
      {
        path: 'login',
        name: 'AdminLogin',
        component: AdminLogin,
        meta: { title: '管理员登录' }
      },
      {
        path: 'dashboard',
        name: 'AdminDashboard',
        component: AdminDashboard,
        meta: { title: '管理首页', requiresAuth: true }
      },
      {
        path: 'students',
        name: 'AdminStudents',
        component: AdminStudents,
        meta: { title: '学生管理', requiresAuth: true }
      },
      {
        path: 'majors',
        name: 'AdminMajors',
        component: AdminMajors,
        meta: { title: '专业管理', requiresAuth: true }
      },
      {
        path: 'classes',
        name: 'AdminClasses',
        component: AdminClasses,
        meta: { title: '班级管理', requiresAuth: true }
      },
      {
        path: 'dormitory',
        name: 'AdminDormitory',
        component: AdminDormitory,
        meta: { title: '宿舍管理', requiresAuth: true }
      },
      {
        path: 'registration',
        name: 'AdminRegistration',
        component: AdminRegistration,
        meta: { title: '报到管理', requiresAuth: true }
      },
      {
        path: 'finance',
        name: 'AdminFinance',
        component: AdminFinance,
        meta: { title: '财务管理', requiresAuth: true }
      },
      {
        path: 'notices',
        name: 'AdminNotices',
        component: AdminNotices,
        meta: { title: '通知公告', requiresAuth: true }
      }
    ]
  },
  // 学生端路由
  {
    path: '/student',
    children: [
      {
        path: 'login',
        name: 'StudentLogin',
        component: StudentLogin,
        meta: { title: '学生登录' }
      },
      {
        path: 'home',
        name: 'StudentHome',
        component: StudentHome,
        meta: { title: '学生首页', requiresAuth: true }
      },
      {
        path: 'info-submit',
        name: 'StudentInfoSubmit',
        component: StudentInfoSubmit,
        meta: { title: '信息提交', requiresAuth: true }
      },
      {
        path: 'payment',
        name: 'StudentPayment',
        component: StudentPayment,
        meta: { title: '在线缴费', requiresAuth: true }
      },
      {
        path: 'info-query',
        name: 'StudentInfoQuery',
        component: StudentInfoQuery,
        meta: { title: '信息查询', requiresAuth: true }
      },
      {
        path: 'profile',
        name: 'StudentProfile',
        component: StudentProfile,
        meta: { title: '个人中心', requiresAuth: true }
      },
      {
        path: 'notices',
        name: 'StudentNotices',
        component: StudentNotices,
        meta: { title: '通知公告', requiresAuth: true }
      },
      {
        path: 'schedule',
        name: 'StudentSchedule',
        component: StudentSchedule,
        meta: { title: '日程安排', requiresAuth: true }
      },
      {
        path: 'contact',
        name: 'StudentContact',
        component: StudentContact,
        meta: { title: '联系我们', requiresAuth: true }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫（暂时注释掉，方便预览）
// router.beforeEach((to, from, next) => {
//   if (to.meta.requiresAuth) {
//     // 检查登录状态
//     const isAuthenticated = localStorage.getItem('token')
//     if (!isAuthenticated) {
//       next({ name: to.path.includes('admin') ? 'AdminLogin' : 'StudentLogin' })
//       return
//     }
//   }
//   next()
// })

export default router